﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: SSConfigConnDAL.gen.cs
//
// 模块名称: SSConfigConnDAL
//
// 作者: LPC
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 13-1-29    LPC    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Data;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;
using System.Data.SqlClient;
using Common;
using Model;

namespace DAL
{
    /// <summary>
    /// SSConfigConn表数据访问层
    /// </summary>
    public partial class SSConfigConnDAL: DB
    {
        public SSConfigConnDAL(LoginInfo info)
        {
            base.loginInfo = info;
        }
        /// <summary>
        /// 根据SSConfigID字段获取SSConfigConnInfo实体对象
        /// </summary>
        /// <param name="sSConfigID">SSConfigID</param>
        /// <returns>SSConfigConnInfo实体对象</returns>
        public SSConfigConnInfo GetInfoById(string sSConfigID)
        {
            var list=new List<SSConfigConnInfo>();
           
            //创建DbCommand对象
            HIDB.dbo cmd =base.conn();
            
            //添加输入输出参数
            IDataParameter[] sqlparams = { 
             new SqlParameter("@SSConfigID",sSConfigID)    
            };
            
            //执行命令返回结果
           try
			{
			    DataTable dt=cmd.StoredDataTable("", sqlparams);
                list=CreateSSConfigConnInfo(dt);
			}
			catch (Exception ex)
			{
				Logger.LogError("UP_Sys_RoleInfo_Insert", "UP_Sys_RoleInfo_Insert",0,1,ex,"","");
			}
           if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 往SSConfigConn表内添加新记录
        /// </summary>
        /// <param name="SSConfigConnInfo">SSConfigConnInfo实体对象</param>
        /// <returns>添加记录索引值</returns>
        public int Insert(SSConfigConnInfo sSConfigConnInfo)
        {
             int num = -1;
            
            //创建cmd对象
            HIDB.dbo cmd =base.conn();
            
             //添加输入输出参数
            IDataParameter[] sqlparams = {
            new SqlParameter("@SSConfigID",sSConfigConnInfo.SSConfigID),
            new SqlParameter("@Connection",sSConfigConnInfo.Connection),
            };
            
            //执行命令返回结果
           	try
				{
					cmd.StoredUpdate("UP_Sys_RoleInfo_Insert", sqlparams);
					num = 1;
				}
				catch (Exception ex)
				{
					Logger.LogError("UP_Sys_RoleInfo_Insert", "UP_Sys_RoleInfo_Insert",0,1,ex,"","");
				}
				return num;
        }
        
        /// <summary>
        /// 更新SSConfigConn表记录
        /// </summary>
        /// <param name="SSConfigConnInfo">SSConfigConnInfo实体对象</param>
        public int Update(SSConfigConnInfo sSConfigConnInfo)
        {
             int num = -1;
            
             //创建cmd对象
            HIDB.dbo cmd =base.conn();
            
             //添加输入输出参数
            IDataParameter[] sqlparams = {
            new SqlParameter("@SSConfigID",sSConfigConnInfo.SSConfigID),
            new SqlParameter("@Connection",sSConfigConnInfo.Connection),
            };
            
             //执行命令返回结果
            try
				{
					cmd.StoredUpdate("UP_Sys_RoleInfo_Insert", sqlparams);
					num = 1;
				}
				catch (Exception ex)
				{
					Logger.LogError("UP_Sys_RoleInfo_Insert", "UP_Sys_RoleInfo_Insert",0,1,ex,"","");
				}

				return num;
        }
        
        /// <summary>
        /// 根据SSConfigID字段删除SSConfigConnInfo表信息
        /// </summary>
        /// <param name="sSConfigID">SSConfigID</param>
        public int Delete(string sSConfigID)
        {
              int num = -1;
            
             //创建Database对象          
            HIDB.dbo cmd =base.conn();
            
             //添加输入输出参数
            IDataParameter[] sqlparams = {
            new SqlParameter("@SSConfigID",sSConfigID),            
            };
            
             //执行命令返回结果
            try
				{
					cmd.StoredUpdate("UP_Sys_RoleInfo_Insert", sqlparams);
					num = 1;
				}
				catch (Exception ex)
				{
					Logger.LogError("UP_Sys_RoleInfo_Insert", "UP_Sys_RoleInfo_Insert",0,1,ex,"","");
				}
				return num;
        }
        
        /// <summary>
        /// 生成SSConfigConnInfo实体对象
        /// </summary>
        private List<SSConfigConnInfo> CreateSSConfigConnInfo(DataTable dt)
        {
            List<SSConfigConnInfo> list=new List<SSConfigConnInfo>();
           for(int j = 0; j < dt.Rows.Count; j++) { 
            SSConfigConnInfo mySSConfigConnInfo = new SSConfigConnInfo
            {
                SSConfigID = DBConvert.GetString(dt.Rows[j], "SSConfigID"),
                Connection = DBConvert.GetString(dt.Rows[j], "Connection")
            };
            list.Add(mySSConfigConnInfo);
            }
            return list;
        }
    }
}